package com.example.file;

import org.w3c.dom.Node;

import java.util.Stack;

/**
 * @author: dangwen
 * @createDate: 2021/7/7
 */
public class Node2 {

    private Integer value;
    private Node2 next;

    public static void main(String[] args) {




        //4-5
        Node2 node1 = new Node2();
        node1.value = 4;
        Node2 node3 = new Node2();
        node3.value = 5;
        node1.next = node3;

        //6-9-5
        Node2 node2 = new Node2();
        node2.value = 6;
        Node2 node4 = new Node2();
        node4.value = 9;
        node2.next = node4;
        Node2 node6 = new Node2();
        node6.value = 5;
        node4.next = node6;

        Node2 newNode =new Node2();
        Node2 tail = newNode;


        //结果7-4-0
//        Node node3=add(node1,node2);
        int high =  0;
        while (node1 != null || node2 != null){
            if (node1 != null && node2 != null){
                int v1 = node1.value;
                int v2 = node2.value;
                newNode.value = (v1+v2 +high) %10;
                high = (v1+v2+high)/10;
                node1 = node1.next;
                node2 = node2.next;
            }else {
                if (node1 == null){
                    int v2 = node2.value;
                    high = (v2+high)/10;
                    newNode.value = (v2 +high) %10;

                    node2 = node2.next;
                }else {
                    int v1 = node1.value;
                    high = (v1+high)/10;
                    newNode.value = (v1+high) %10;

                    node1 = node1.next;
                }

            }
            newNode.next = new Node2();
            newNode = newNode.next;
        }


        while (tail != null){
            System.out.println(tail.value+"->");
            tail = tail.next;
        }

    }

}
